#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a),i##END=(b);i<=i##END;i++)
#define Rof(i,b,a) for(int i=(b),i##END=(a);i>=i##END;i--)
#define go(u) for(int i=head[u];i;i=nxt[i])
#define ll long long
//#define int long long
using namespace std;
char buf[(1<<21)+5],*p1,*p2;
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin)),p1==p2?EOF:*p1++)
inline int read(){
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
    return x*f;
}
bool ST;
const int N=8e5+10;
int n;ll ans[N],now;
int head[N],to[N<<1],nxt[N<<1],cnt;
void addedge(int u,int v){
	to[++cnt]=v,nxt[cnt]=head[u],head[u]=cnt;
}
//#define C2(n) (1ll*(n)*((n)-1)/2)
inline ll C2(int n){return 1ll*n*(n-1)/2;}
struct node{
	int u,v,w,id;
	bool operator < (const node &x) const {return w>x.w;}
}e[N];
int dfn[N],sz[N],idx,fa[N];
void dfs(int u,int f){
	fa[u]=f,dfn[u]=++idx,sz[u]=1;
	go(u){int v=to[i];if(v!=f)dfs(v,u),sz[u]+=sz[v];}
}
int Fa[N];
int get(int x){return Fa[x]==x?x:Fa[x]=get(Fa[x]);}
void merge(int x,int y){//Fa[x]=y
	x=get(x),y=get(y),Fa[x]=y;
}
int c[N],vis[N];
#define lowbit(x) (x&-x)
void add(int u,int v){if(u)for(int i=u;i<=n;i+=lowbit(i))c[i]+=v;}
int ask(int u,int s=0){for(int i=u;i;i-=lowbit(i))s+=c[i];return s;}
#define getsz(u) (ask(dfn[u]+sz[u]-1)-ask(dfn[u]-1))
ll out[N];
ll c2[N];
void adde(node x){
	int u=x.u,v=x.v;
	if(!vis[u])vis[u]=1,add(dfn[u],1),add(dfn[fa[u]],-1);
	if(!vis[v])vis[v]=1,add(dfn[v],1),add(dfn[fa[v]],-1);
	int rt=get(u);merge(v,u);//u~rt,+=sz[v]
	int ADD=getsz(v),SZ=getsz(rt);
	now-=C2(ADD)+C2(SZ);
	add(dfn[u],ADD),add(dfn[fa[rt]],-ADD);
	now+=C2(SZ+ADD);
}
int stk[30],tp;
void write(ll x){
	do stk[++tp]=x%10,x/=10;while(x);
	while(tp)putchar(stk[tp--]^48);
}
bool ED;
signed main(){
//	printf("%.2lf MB\n",abs(&ED-&ST)/1024.0/1024.0);
	freopen("tatooine.in","r",stdin);
	freopen("tatooine.out","w",stdout);
	n=read();For(i,1,n-1){
		int u=read(),v=read(),w=read();
		e[i]=(node){u,v,w,i};
		addedge(u,v),addedge(v,u);
	}For(i,1,n)c2[i]=1ll*i*(i-1)/2;
	sort(e+1,e+n),dfs(1,0);For(i,1,n)Fa[i]=i;now=0;
	For(i,1,n-1){if(fa[e[i].u]==e[i].v)swap(e[i].u,e[i].v);}
	int j=1,u,v,siz,del;Rof(k,20,1){
		while(j<n&&e[j].w==k)adde(e[j++]);
		For(i,1,n-1){
			ll add=now;
			if(e[i].w>=k)u=e[i].u,v=e[i].v,siz=getsz(get(u)),del=getsz(v),add+=c2[del]+c2[siz-del]-c2[siz];
			ans[i]+=add;
		}
	}For(i,1,n-1)out[e[i].id]=ans[i];For(i,1,n-1)write(out[i]),putchar('\n');
	return 0;
}
